#include "udf_global.h"

#if ( UDF_EN_16 > 0 && !defined(UDP_SUB_PROJECT) && !defined(UDT_SUB_PROJECT) && (defined(UDF16_SUB_PROJECT) || defined(UDF_PRJ)) )

#include "udsf.h"

// NOTICE: 仅XIP方式支持重写中断响应函数
void UDF16_udf_handle( int handler_id )
{
#if 0  // rom内置中断响应函数，可在udf16内重写，使用sUDF_global定义全局变量，不再使用gPara全局变量!!!
	if( handler_id == SysTick_IRQn ){
		gPara.SysTick_cnt ++;
	}else if( handler_id == USCI1_IRQn ){
		uint32_t reg_isr = 0;
		reg_isr = USCI1->ISR;
		uint8_t data;
		//	SYSC->CLK_SEL&=~LRC_DIV128_MSK; //128K clk
		//RX
		if(reg_isr&USCI_ISR_RXNE_Msk)
		{
			switch(gPara.WorkMode){
				case 0: //config
					data = USCI1->TRX;
					if(gPara.strUart.RecFinish)
						return;
					gPara.strUart.timeoutStart = 1;
					gPara.strUart.timeoutCnt = 0;

					if(data==0x0A){
						gPara.strUart.RecFinish = 1;
						gPara.strUart.timeoutCnt = 0;
						gPara.strUart.timeoutStart = 0;
					}
					if(gPara.strUart.RecLen<(UART_REC_MAX_LEN-1)){
						gPara.strUart.RecBuff[gPara.strUart.RecLen] = data;
						gPara.strUart.RecLen++;
					}
					break;
				case 1: //func
					SYSC->CLK_EN |= WDT_PATTERN_EN_Msk; // ENABLE WDT clock  	
					WDT->CMP = 0;	
					WDT->STR = 0x1;						// bit0:clear
					while(1);
			}	
			//ERR
			if(reg_isr&0x10)
			{
					//printf("[CONS]config reg_isr ERROR! %08X\r\n",reg_isr);
					USCI1->ISR=0x10;
			}
		}
	}else{
		while(1);
	}
	#endif
}

#endif
